From df1816a29cb5e7b37494aaf7f92fcd6bba98e7ef Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 17 Apr 2020 00:20:09 -0400 Subject: [PATCH] button: Drop relief We are only using this as a boolean, so change it to a boolean property named has-frame. --- .../constraint-editor-window.c | 6 +- demos/gtk-demo/demotaggedentry.c | 2 +- demos/gtk-demo/dnd.c | 14 ++-- demos/gtk-demo/fishbowl.ui | 2 +- demos/gtk-demo/listbox.ui | 14 ++-- demos/widget-factory/widget-factory.ui | 8 +- docs/reference/gtk/gtk4-sections.txt | 4 +- gtk/gtkbutton.c | 75 +++++++++---------- gtk/gtkbutton.h | 6 +- gtk/gtklinkbutton.c | 2 +- gtk/gtkmenubutton.c | 10 ++- gtk/gtknotebook.c | 2 +- gtk/gtkplacesview.c | 2 +- gtk/inspector/css-editor.ui | 4 +- gtk/inspector/data-list.ui | 2 +- gtk/inspector/object-tree.c | 2 +- gtk/inspector/recorder.c | 4 +- gtk/inspector/recorder.ui | 8 +- gtk/inspector/window.ui | 4 +- gtk/ui/gtkemojichooser.ui | 20 ++--- gtk/ui/gtkscalebutton.ui | 6 +- tests/testtreelistmodel.c | 2 +- testsuite/gtk/focus-chain/widget-factory.ui | 8 +- testsuite/gtk/focus-chain/widget-factory2.ui | 6 +- testsuite/gtk/focus-chain/widget-factory3.ui | 8 +- testsuite/reftests/link-coloring.ui | 4 +- 26 files changed, 111 insertions(+), 114 deletions(-) diff --git a/demos/constraint-editor/constraint-editor-window.c b/demos/constraint-editor/constraint-editor-window.c index 4c0db5e5d2..cf2c11e2fd 100644 --- a/demos/constraint-editor/constraint-editor-window.c +++ b/demos/constraint-editor/constraint-editor-window.c @@ -613,19 +613,19 @@ create_widget_func (gpointer item, if (GTK_IS_CONSTRAINT (item) || GTK_IS_CONSTRAINT_GUIDE (item)) { button = gtk_button_new_from_icon_name ("document-edit-symbolic"); - gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (button), FALSE); g_signal_connect (button, "clicked", G_CALLBACK (row_edit), win); g_object_set_data (G_OBJECT (row), "edit", button); gtk_container_add (GTK_CONTAINER (box), button); button = gtk_button_new_from_icon_name ("edit-delete-symbolic"); - gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (button), FALSE); g_signal_connect (button, "clicked", G_CALLBACK (row_delete), win); gtk_container_add (GTK_CONTAINER (box), button); } else if (GTK_IS_WIDGET (item)) { button = gtk_button_new_from_icon_name ("edit-delete-symbolic"); - gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (button), FALSE); g_signal_connect (button, "clicked", G_CALLBACK (row_delete), win); gtk_container_add (GTK_CONTAINER (box), button); } diff --git a/demos/gtk-demo/demotaggedentry.c b/demos/gtk-demo/demotaggedentry.c index dcba5a435d..ba2b348839 100644 --- a/demos/gtk-demo/demotaggedentry.c +++ b/demos/gtk-demo/demotaggedentry.c @@ -472,7 +472,7 @@ demo_tagged_entry_tag_set_has_close_button (DemoTaggedEntryTag *tag, gtk_container_add (GTK_CONTAINER (tag->button), image); gtk_widget_set_halign (tag->button, GTK_ALIGN_CENTER); gtk_widget_set_valign (tag->button, GTK_ALIGN_CENTER); - gtk_button_set_relief (GTK_BUTTON (tag->button), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (tag->button), FALSE); gtk_container_add (GTK_CONTAINER (tag->box), tag->button); g_signal_connect (tag->button, "clicked", G_CALLBACK (on_button_clicked), tag); } diff --git a/demos/gtk-demo/dnd.c b/demos/gtk-demo/dnd.c index c9491ae958..118f0f5ec8 100644 --- a/demos/gtk-demo/dnd.c +++ b/demos/gtk-demo/dnd.c @@ -279,11 +279,11 @@ pressed_cb (GtkGesture *gesture, gtk_container_add (GTK_CONTAINER (menu), box); item = gtk_button_new_with_label ("New Label"); - gtk_button_set_relief (GTK_BUTTON (item), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (item), FALSE); g_signal_connect (item, "clicked", G_CALLBACK (new_label_cb), widget); gtk_container_add (GTK_CONTAINER (box), item); item = gtk_button_new_with_label ("New Spinner"); - gtk_button_set_relief (GTK_BUTTON (item), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (item), FALSE); g_signal_connect (item, "clicked", G_CALLBACK (new_spinner_cb), widget); gtk_container_add (GTK_CONTAINER (box), item); @@ -291,7 +291,7 @@ pressed_cb (GtkGesture *gesture, gtk_container_add (GTK_CONTAINER (box), item); item = gtk_button_new_with_label ("Edit"); - gtk_button_set_relief (GTK_BUTTON (item), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (item), FALSE); gtk_widget_set_sensitive (item, child != NULL && child != widget); g_signal_connect (item, "clicked", G_CALLBACK (edit_cb), child); gtk_container_add (GTK_CONTAINER (box), item); @@ -300,24 +300,24 @@ pressed_cb (GtkGesture *gesture, gtk_container_add (GTK_CONTAINER (box), item); item = gtk_button_new_with_label ("Cut"); - gtk_button_set_relief (GTK_BUTTON (item), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (item), FALSE); gtk_widget_set_sensitive (item, child != NULL && child != widget); g_signal_connect (item, "clicked", G_CALLBACK (cut_cb), child); gtk_container_add (GTK_CONTAINER (box), item); item = gtk_button_new_with_label ("Copy"); - gtk_button_set_relief (GTK_BUTTON (item), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (item), FALSE); gtk_widget_set_sensitive (item, child != NULL && child != widget); g_signal_connect (item, "clicked", G_CALLBACK (copy_cb), child); gtk_container_add (GTK_CONTAINER (box), item); item = gtk_button_new_with_label ("Paste"); - gtk_button_set_relief (GTK_BUTTON (item), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (item), FALSE); clipboard = gdk_display_get_clipboard (gdk_display_get_default ()); gtk_widget_set_sensitive (item, gdk_content_formats_contain_gtype (gdk_clipboard_get_formats (clipboard), GTK_TYPE_DEMO_WIDGET)); g_signal_connect (item, "clicked", G_CALLBACK (paste_cb), widget); gtk_container_add (GTK_CONTAINER (box), item); item = gtk_button_new_with_label ("Delete"); - gtk_button_set_relief (GTK_BUTTON (item), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (item), FALSE); gtk_widget_set_sensitive (item, child != NULL && child != widget); g_signal_connect (item, "clicked", G_CALLBACK (delete_cb), child); gtk_container_add (GTK_CONTAINER (box), item); diff --git a/demos/gtk-demo/fishbowl.ui b/demos/gtk-demo/fishbowl.ui index df065d48a4..3805724437 100644 --- a/demos/gtk-demo/fishbowl.ui +++ b/demos/gtk-demo/fishbowl.ui @@ -49,7 +49,7 @@ changes-allow - none + 0 diff --git a/demos/gtk-demo/listbox.ui b/demos/gtk-demo/listbox.ui index 8588bf79e6..c43ec2321a 100644 --- a/demos/gtk-demo/listbox.ui +++ b/demos/gtk-demo/listbox.ui @@ -40,7 +40,7 @@ 1 baseline - none + 0 baseline @@ -109,7 +109,7 @@ reshareer 1 - none + 0 http://www.gtk.org @@ -126,7 +126,7 @@ Expand 1 - none + 0 @@ -138,14 +138,14 @@ Reply 1 - none + 0 Reshare 1 - none + 0 @@ -153,7 +153,7 @@ Favorite 1 - none + 0 @@ -223,7 +223,7 @@ FAVORITES Details 1 - none + 0 diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui index e7c30454e3..ff76f86d27 100644 --- a/demos/widget-factory/widget-factory.ui +++ b/demos/widget-factory/widget-factory.ui @@ -864,7 +864,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus. link button 1 1 - none + 0 http://www.gtk.org @@ -1449,7 +1449,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus. 0 - none + 0 window-close-symbolic @@ -2664,7 +2664,7 @@ microphone-sensitivity-medium-symbolic - none + 0 0 window-close-symbolic @@ -2696,7 +2696,7 @@ microphone-sensitivity-medium-symbolic - none + 0 0 window-close-symbolic diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index a5ff7e1261..0b32fd1d4a 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -520,8 +520,8 @@ gtk_button_new gtk_button_new_with_label gtk_button_new_with_mnemonic gtk_button_new_from_icon_name -gtk_button_set_relief -gtk_button_get_relief +gtk_button_set_has_frame +gtk_button_get_has_frame gtk_button_get_label gtk_button_set_label gtk_button_get_use_underline diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 6ad1fb6304..b1be03fa9f 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -102,7 +102,7 @@ enum { enum { PROP_0, PROP_LABEL, - PROP_RELIEF, + PROP_HAS_FRAME, PROP_USE_UNDERLINE, PROP_ICON_NAME, @@ -228,13 +228,12 @@ gtk_button_class_init (GtkButtonClass *klass) FALSE, GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); - props[PROP_RELIEF] = - g_param_spec_enum ("relief", - P_("Border relief"), - P_("The border relief style"), - GTK_TYPE_RELIEF_STYLE, - GTK_RELIEF_NORMAL, - GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); + props[PROP_HAS_FRAME] = + g_param_spec_boolean ("has-frame", + P_("Has Frame"), + P_("Whether the button has a frame"), + TRUE, + GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY); props[PROP_ICON_NAME] = g_param_spec_string ("icon-name", @@ -484,8 +483,8 @@ gtk_button_set_property (GObject *object, case PROP_LABEL: gtk_button_set_label (button, g_value_get_string (value)); break; - case PROP_RELIEF: - gtk_button_set_relief (button, g_value_get_enum (value)); + case PROP_HAS_FRAME: + gtk_button_set_has_frame (button, g_value_get_boolean (value)); break; case PROP_USE_UNDERLINE: gtk_button_set_use_underline (button, g_value_get_boolean (value)); @@ -519,8 +518,8 @@ gtk_button_get_property (GObject *object, case PROP_LABEL: g_value_set_string (value, gtk_button_get_label (button)); break; - case PROP_RELIEF: - g_value_set_enum (value, gtk_button_get_relief (button)); + case PROP_HAS_FRAME: + g_value_set_boolean (value, gtk_button_get_has_frame (button)); break; case PROP_USE_UNDERLINE: g_value_set_boolean (value, priv->use_underline); @@ -641,51 +640,45 @@ gtk_button_new_with_mnemonic (const gchar *label) } /** - * gtk_button_set_relief: - * @button: The #GtkButton you want to set relief styles of - * @relief: The GtkReliefStyle as described above + * gtk_Button_set_has_frame: + * @button: a #GtkButton + * @has_frame: whether the button should have a visible frame * - * Sets the relief style of the edges of the given #GtkButton widget. - * Two styles exist, %GTK_RELIEF_NORMAL and %GTK_RELIEF_NONE. - * The default style is, as one can guess, %GTK_RELIEF_NORMAL. + * Sets the style of the button. Buttons can has a flat appearance + * or have a frame drawn around them. */ void -gtk_button_set_relief (GtkButton *button, - GtkReliefStyle relief) +gtk_button_set_has_frame (GtkButton *button, + gboolean has_frame) { - GtkReliefStyle old_relief; g_return_if_fail (GTK_IS_BUTTON (button)); - old_relief = gtk_button_get_relief (button); - if (old_relief != relief) - { - if (relief == GTK_RELIEF_NONE) - gtk_widget_add_css_class (GTK_WIDGET (button), GTK_STYLE_CLASS_FLAT); - else - gtk_widget_remove_css_class (GTK_WIDGET (button), GTK_STYLE_CLASS_FLAT); + if (gtk_button_get_has_frame (button) == has_frame) + return; - g_object_notify_by_pspec (G_OBJECT (button), props[PROP_RELIEF]); - } + if (has_frame) + gtk_widget_remove_css_class (GTK_WIDGET (button), GTK_STYLE_CLASS_FLAT); + else + gtk_widget_add_css_class (GTK_WIDGET (button), GTK_STYLE_CLASS_FLAT); + + g_object_notify_by_pspec (G_OBJECT (button), props[PROP_HAS_FRAME]); } /** - * gtk_button_get_relief: - * @button: The #GtkButton you want the #GtkReliefStyle from. + * gtk_button_get_has_frame: + * @button: a #GtkButton * - * Returns the current relief style of the given #GtkButton. + * Returns whether the button has a frame. * - * Returns: The current #GtkReliefStyle + * Returns: %TRUE if the button has a frame */ -GtkReliefStyle -gtk_button_get_relief (GtkButton *button) +gboolean +gtk_button_get_has_frame (GtkButton *button) { - g_return_val_if_fail (GTK_IS_BUTTON (button), GTK_RELIEF_NORMAL); + g_return_val_if_fail (GTK_IS_BUTTON (button), TRUE); - if (gtk_widget_has_css_class (GTK_WIDGET (button), GTK_STYLE_CLASS_FLAT)) - return GTK_RELIEF_NONE; - else - return GTK_RELIEF_NORMAL; + return !gtk_widget_has_css_class (GTK_WIDGET (button), GTK_STYLE_CLASS_FLAT); } static void diff --git a/gtk/gtkbutton.h b/gtk/gtkbutton.h index f3738f9166..9a4b15c992 100644 --- a/gtk/gtkbutton.h +++ b/gtk/gtkbutton.h @@ -86,10 +86,10 @@ GDK_AVAILABLE_IN_ALL GtkWidget* gtk_button_new_with_mnemonic (const gchar *label); GDK_AVAILABLE_IN_ALL -void gtk_button_set_relief (GtkButton *button, - GtkReliefStyle relief); +void gtk_button_set_has_frame (GtkButton *button, + gboolean has_frame); GDK_AVAILABLE_IN_ALL -GtkReliefStyle gtk_button_get_relief (GtkButton *button); +gboolean gtk_button_get_has_frame (GtkButton *button); GDK_AVAILABLE_IN_ALL void gtk_button_set_label (GtkButton *button, const gchar *label); diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c index ee82086798..a260f146cf 100644 --- a/gtk/gtklinkbutton.c +++ b/gtk/gtklinkbutton.c @@ -345,7 +345,7 @@ gtk_link_button_init (GtkLinkButton *link_button) GdkContentProvider *content; GtkDragSource *source; - gtk_button_set_relief (GTK_BUTTON (link_button), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (link_button), FALSE); gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK, FALSE); gtk_widget_set_has_tooltip (GTK_WIDGET (link_button), TRUE); diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c index c210d096d0..3e9f78ca4a 100644 --- a/gtk/gtkmenubutton.c +++ b/gtk/gtkmenubutton.c @@ -946,12 +946,15 @@ void gtk_menu_button_set_relief (GtkMenuButton *menu_button, GtkReliefStyle relief) { + gboolean has_frame; + g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button)); - if (relief == gtk_button_get_relief (GTK_BUTTON (menu_button->button))) + has_frame = relief == GTK_RELIEF_NORMAL; + if (gtk_button_get_has_frame (GTK_BUTTON (menu_button->button)) == has_frame) return; - gtk_button_set_relief (GTK_BUTTON (menu_button->button), relief); + gtk_button_set_has_frame (GTK_BUTTON (menu_button->button), has_frame); g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_RELIEF]); } @@ -968,7 +971,8 @@ gtk_menu_button_get_relief (GtkMenuButton *menu_button) { g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), GTK_RELIEF_NORMAL); - return gtk_button_get_relief (GTK_BUTTON (menu_button->button)); + return gtk_button_get_has_frame (GTK_BUTTON (menu_button->button)) + ? GTK_RELIEF_NORMAL : GTK_RELIEF_NONE; } /** diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 277138fe32..1faaf5f8ea 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -5545,7 +5545,7 @@ gtk_notebook_menu_item_create (GtkNotebook *notebook, } menu_item = gtk_button_new (); - gtk_button_set_relief (GTK_BUTTON (menu_item), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (menu_item), FALSE); gtk_container_add (GTK_CONTAINER (menu_item), page->menu_label); gtk_container_add (GTK_CONTAINER (notebook->menu_box), menu_item); g_signal_connect (menu_item, "clicked", diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c index 415358486f..4a66513b03 100644 --- a/gtk/gtkplacesview.c +++ b/gtk/gtkplacesview.c @@ -610,7 +610,7 @@ populate_servers (GtkPlacesView *view) button = gtk_button_new_from_icon_name ("window-close-symbolic"); gtk_widget_set_halign (button, GTK_ALIGN_END); gtk_widget_set_valign (button, GTK_ALIGN_CENTER); - gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (button), FALSE); gtk_widget_add_css_class (button, "sidebar-button"); gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 2); diff --git a/gtk/inspector/css-editor.ui b/gtk/inspector/css-editor.ui index 50b9bee503..dc4649904c 100644 --- a/gtk/inspector/css-editor.ui +++ b/gtk/inspector/css-editor.ui @@ -29,7 +29,7 @@ 6 - none + 0 Disable this custom CSS media-playback-pause-symbolic @@ -37,7 +37,7 @@ - none + 0 Save the current CSS document-save-symbolic diff --git a/gtk/inspector/data-list.ui b/gtk/inspector/data-list.ui index 19549a9834..78e2369777 100644 --- a/gtk/inspector/data-list.ui +++ b/gtk/inspector/data-list.ui @@ -10,7 +10,7 @@ 6 - none + 0 Show data view-refresh-symbolic diff --git a/gtk/inspector/object-tree.c b/gtk/inspector/object-tree.c index a1a8760f4d..bc720a4b19 100644 --- a/gtk/inspector/object-tree.c +++ b/gtk/inspector/object-tree.c @@ -1020,7 +1020,7 @@ gtk_inspector_object_tree_create_list_widget (gpointer row_item, child = g_object_new (GTK_TYPE_BOX, "css-name", "expander", NULL); title = g_object_new (GTK_TYPE_TOGGLE_BUTTON, "css-name", "title", NULL); - gtk_button_set_relief (GTK_BUTTON (title), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (title), FALSE); g_object_bind_property (row_item, "expanded", title, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); gtk_container_add (GTK_CONTAINER (child), title); diff --git a/gtk/inspector/recorder.c b/gtk/inspector/recorder.c index b4ed3d965e..ac7f728f7f 100644 --- a/gtk/inspector/recorder.c +++ b/gtk/inspector/recorder.c @@ -324,7 +324,7 @@ create_widget_for_render_node (gpointer row_item, child = g_object_new (GTK_TYPE_BOX, "css-name", "expander", NULL); title = g_object_new (GTK_TYPE_TOGGLE_BUTTON, "css-name", "title", NULL); - gtk_button_set_relief (GTK_BUTTON (title), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (title), FALSE); g_object_bind_property (row_item, "expanded", title, "active", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); gtk_container_add (GTK_CONTAINER (child), title); g_object_set_data_full (G_OBJECT (row), "make-sure-its-not-unreffed", g_object_ref (row_item), g_object_unref); @@ -1117,7 +1117,7 @@ gtk_inspector_recorder_recordings_list_create_widget (gpointer item, gtk_container_add (GTK_CONTAINER (hbox), label); button = gtk_toggle_button_new (); - gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_button_set_has_frame (GTK_BUTTON (button), FALSE); gtk_button_set_icon_name (GTK_BUTTON (button), "view-more-symbolic"); gtk_container_add (GTK_CONTAINER (hbox), button); diff --git a/gtk/inspector/recorder.ui b/gtk/inspector/recorder.ui index 54fed8871e..c3e6d2071e 100644 --- a/gtk/inspector/recorder.ui +++ b/gtk/inspector/recorder.ui @@ -13,7 +13,7 @@ 6 - none + 0 media-record-symbolic Record frames @@ -21,7 +21,7 @@ - none + 0 edit-clear-all-symbolic Clear recorded frames @@ -29,7 +29,7 @@ - none + 0 insert-object-symbolic Add debug nodes @@ -39,7 +39,7 @@ - none + 0 0 document-save-as-symbolic Save selected node diff --git a/gtk/inspector/window.ui b/gtk/inspector/window.ui index 4623a72229..4fc07bcfc8 100644 --- a/gtk/inspector/window.ui +++ b/gtk/inspector/window.ui @@ -230,7 +230,7 @@ go-previous-symbolic Toggle Sidebar - none + 0 6 6 6 @@ -262,7 +262,7 @@ 6 view-refresh-symbolic Refresh action state - none + 0 diff --git a/gtk/ui/gtkemojichooser.ui b/gtk/ui/gtkemojichooser.ui index ad7ad0191b..388761ca0d 100644 --- a/gtk/ui/gtkemojichooser.ui +++ b/gtk/ui/gtkemojichooser.ui @@ -215,7 +215,7 @@ - none + 0 Recent